package com.ddn.service.room.impl;

import com.ddn.mapper.roomManagement.VipMapper;
import com.ddn.model.roomManagement.VipPieVO;
import com.ddn.model.roomManagement.VipUser;
import com.ddn.model.roomManagement.VipBarVO;
import com.ddn.service.room.VipService;
import com.ddn.util.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author XieYp
 * @desc
 * @date 2023/1/1
 */
@Service
public class VipServiceImpl implements VipService {

    @Autowired
    private VipMapper vipMapper;


    @Override
    public ResultData findAll(HashMap<String, Object> map) {
        String pageNo = (String) map.get("page");
        String pageSize = (String) map.get("limit");

        PageHelper.startPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));

        // 查询全部
        List<VipUser> list = vipMapper.findAll(map);
        PageInfo<VipUser> info = new PageInfo<>( list );
        // 计数
        return ResultData.ok(list, (int) info.getTotal());
    }

    @Override
    public ResultData addVip(HashMap<String, Object> map) {
        boolean isOk = vipMapper.addVip(map);
        if (isOk) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData deleteVip(HashMap<String, Object> map) {
        boolean isOk = vipMapper.deleteVip(map);
        if (isOk){
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData updateVip(HashMap<String, Object> map) {
        boolean isOk = vipMapper.updateVip(map);
        if (isOk){
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData deleteBatch(int[] ids) {
        boolean isOk = vipMapper.deleteBatch(ids);
        if (isOk) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData vipBar() {
        List<VipBarVO> vipBarVOS = vipMapper.vipBar();
        if (vipBarVOS !=null) {
            return ResultData.ok(vipBarVOS);
        }
        return ResultData.fail();
    }

    @Override
    public ResultData vipPie() {
        List<VipPieVO> vipPieVOS = vipMapper.vipPie();
        if (vipPieVOS !=null) {
            return ResultData.ok(vipPieVOS);
        }
        return ResultData.fail();
    }

}
